<template>
  <el-card>
    <div class="flex-content">
      <el-table
        v-loading="isLoading.table"
        :data="dataList"
        style="width: 100%"
      >
        <el-table-column
          align="center"
          label="公司"
          prop="name"
          show-overflow-tooltip
        >
        </el-table-column>

        <el-table-column align="center" label="状态">
          <template v-slot="{ row }">
            <el-button
              v-if="row.status.origin === 1"
              size="mini"
              type="success"
              @click="handleState(row)"
            >
              {{ row.status.trans }}
            </el-button>
            <el-button
              v-if="row.status.origin === 0"
              size="mini"
              type="danger"
              @click="handleState(row)"
            >
              {{ row.status.trans }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-card>
</template>

<script>
import { lists as getList, state } from "@/api/expressCompany";

export default {
  name: "ExpressCompany",
  data() {
    return {
      // 列表
      dataList: [],
      // 详情
      dataInfo: {},
      // 加载
      isLoading: {
        table: false,
      },
      // 防抖
      queryId: +new Date(),
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // 列表
    getData() {
      this.isLoading.table = true;
      this.queryId++;
      let queryId = this.queryId;
      getList()
        .then((res) => {
          if (queryId !== this.queryId) {
            return;
          }

          this.dataList = res.data.list;
        })
        .finally(() => {
          this.isLoading.table = false;
        });
    },
    // 状态
    handleState(row) {
      this.$confirm("是否要修改状态?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        callback: () => {},
        beforeClose: (action, ctx, close) => {
          if (action !== "confirm") {
            this.$message({
              type: "info",
              message: "已取消操作",
            });
            close();
            return false;
          } else {
            ctx.confirmButtonLoading = true;
            state({
              express_id: row.express_id,
            })
              .then(() => {
                this.getData();
                close();
              })
              .catch(() => {})
              .finally(() => {
                ctx.confirmButtonLoading = false;
              });
          }
        },
      });
    },
    // 重置页面数据
    handleResetPage() {
      this.queryInfo.page = 1;
      this.getData();
    },
    //关闭
    closeDialog(val) {
      if (!val) {
        this.getData();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.header-box {
  min-height: 40px;
}

.thumb-box {
  width: 100px;
  height: 50px;
  display: flex;
  align-items: center;
}
</style>
